#nullable enable

using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using PHMEE.EntityFrameworkCore;

namespace PHMEE.EnergyEfficiency;

public class TimeSeriesTombstonesRepository : ITimeSeriesTombstonesRepository
{
    private readonly PHMEEDbContext _context;
    
    public TimeSeriesTombstonesRepository(PHMEEDbContext context)
    {
        _context = context;
    }
    
    public Task<TimeSeriesTombstones?> GetOrDefaultAsync(Guid vesselId, DateTime ts, SyncDataType syncDataType)
    {
        return _context.TimeSeriesTombstones
            .FirstOrDefaultAsync(c => c.VesselId == vesselId && c.Ts == ts && c.SyncDataType == syncDataType);
    }
    
    public async Task InsertAsync(TimeSeriesTombstones timeSeriesTombstones)
    {
        await _context.TimeSeriesTombstones.AddAsync(timeSeriesTombstones);
        await _context.SaveChangesAsync();
    }

}